package org.quasar.airNova.presentationLayer;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.quasar.airNova.businessLayer.Sexo;

public class CriarEmpresa extends JPanel {

	private static final long serialVersionUID = 1L;
	private JTextField nNIFJTF;
	private JTextField moradaJTF;
	private JTextField nomeJTF;
	private JTextField nWebsiteJTF;
	private Gui gui;

	/**
	 * Create the panel.
	 */
	public CriarEmpresa(Gui gui) {
		setGui(gui);
		setLayout(new BorderLayout(0, 0));
		this.setSize(500, 350);
		JPanel panel = new JPanel();
		add(panel, BorderLayout.CENTER);
		panel.setLayout(null);

		JLabel lblNewLabel = new JLabel("NIF");
		lblNewLabel.setBounds(40, 76, 151, 14);
		panel.add(lblNewLabel);

		nNIFJTF = new JTextField();
		nNIFJTF.setBounds(231, 67, 203, 20);
		panel.add(nNIFJTF);
		nNIFJTF.setColumns(10);

		JLabel lblNewLabel_2 = new JLabel("Morada");
		lblNewLabel_2.setBounds(40, 98, 126, 14);
		panel.add(lblNewLabel_2);

		moradaJTF = new JTextField();
		moradaJTF.setBounds(231, 95, 203, 20);
		panel.add(moradaJTF);
		moradaJTF.setColumns(10);

		JLabel lblNewLabel_1 = new JLabel("Nome");
		lblNewLabel_1.setBounds(40, 123, 126, 14);
		panel.add(lblNewLabel_1);

		nomeJTF = new JTextField();
		nomeJTF.setBounds(231, 120, 203, 20);
		panel.add(nomeJTF);
		nomeJTF.setColumns(10);

		JLabel lblNmeroCartaoDe = new JLabel("Website");
		lblNmeroCartaoDe.setBounds(40, 148, 126, 14);
		panel.add(lblNmeroCartaoDe);

		nWebsiteJTF = new JTextField();
		nWebsiteJTF.setBounds(231, 145, 203, 20);
		panel.add(nWebsiteJTF);
		nWebsiteJTF.setColumns(10);

		JButton btnNewButton_2 = new JButton("Apagar Campos");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				nomeJTF.setText("");
				moradaJTF.setText("");
				nNIFJTF.setText("");
				nWebsiteJTF.setText("");
			}
		});
		btnNewButton_2.setBounds(251, 217, 126, 23);
		panel.add(btnNewButton_2);

		JButton btnNewButton = new JButton("Submeter");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(moradaJTF.getText().length() != 0 && nNIFJTF.getText().length() != 0 && nomeJTF.getText().length() != 0 && nWebsiteJTF.getText().length() != 0) {
				AirNova_Database.criarEmpresa(moradaJTF.getText(),
						nNIFJTF.getText(), nomeJTF.getText(),
						nWebsiteJTF.getText());
					closeTab();
				}
			}
		});
		btnNewButton.setBounds(44, 217, 98, 23);
		panel.add(btnNewButton);

		JButton btnNewButton_1 = new JButton("Cancelar");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				closeTab();
			}

			
		});
		btnNewButton_1.setBounds(152, 217, 89, 23);
		panel.add(btnNewButton_1);

		JLabel lblNewLabel_3 = new JLabel("Criar Nova Empresa");
		lblNewLabel_3.setFont(new Font("Tahoma", Font.PLAIN, 17));
		lblNewLabel_3.setBounds(30, 24, 151, 32);
		panel.add(lblNewLabel_3);

	}
	private void closeTab() {
		getGui().getTabbedPane().removeTabAt(
				getGui().getTabbedPane().getSelectedIndex());
	}
	public Gui getGui() {
		return gui;
	}

	public void setGui(Gui gui) {
		this.gui = gui;
	}
}